home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / dev / lang / sbp3_1e.lzh / FAMILY.PL < prev    next >
Text File  |  1991-11-01  |  1KB  |  56 lines

  1. /* From the book PROLOG PROGRAMMING IN DEPTH
  2.    by Michael A. Covington, Donald Nute, and Andre Vellino.
  3.    Copyright 1988 Scott, Foresman & Co.
  4.    Non-commercial distribution of this file is permitted. */
  5.  
  6. /* FAMILY.PL */
  7. /* Part of a family tree expressed in Prolog */
  8.  
  9. /* With "father," "mother," and "parent,"
  10.    the first argument is the parent and
  11.    the second is the son or daughter */
  12.  
  13. father(michael,cathy).
  14. father(charles_gordon,michael).
  15. father(charles_gordon,julie).
  16. father(charles,charles_gordon).
  17. father(jim,melody).
  18. father(jim,crystal).
  19. father(elmo,jim).
  20. father(greg,stephanie).
  21.  
  22. mother(melody,cathy).
  23. mother(hazel,michael).
  24. mother(hazel,julie).
  25. mother(eleanor,melody).
  26. mother(eleanor,crystal).
  27. mother(crystal,stephanie).
  28.  
  29. male(michael).
  30. male(charles_gordon).
  31. male(jim).
  32. male(elmo).
  33. male(greg).
  34.  
  35. female(cathy).
  36. female(julie).
  37. female(crystal).
  38. female(stephanie).
  39. female(hazel).
  40. female(eleanor).
  41. female(melody).
  42.  
  43.  
  44. parent(X,Y) :- father(X,Y).
  45. parent(X,Y) :- mother(X,Y).
  46. sibling(X,Y) :- mother(M,X),mother(M,Y),X\==Y.
  47. ancestor(X,Y) :- parent(X,Z),ancestor(Z,Y).
  48. grandfather(GF,GC)   :- father(F,GC),father(GF,F).
  49. grandfather(GF,GC)   :- mother(F,GC),father(GF,F).
  50. grand_parent(X,Y)    :- parent(X,C),parent(C,Y).
  51. great_grand_parent(X,Y) :- grand_parent(X,C),parent(C,Y).
  52. aunt(A,N)   :- sibling(A,X),parent(X,N),female(A).
  53. uncle(U,N)  :- sibling(U,X),parent(X,N),male(U).
  54. cousin(X,Y) :- sibling(A,B),parent(A,X),parent(B,Y).
  55.  
  56.